package com.skyz.base.util;

import android.content.Context;
import android.content.SharedPreferences;

public class SpReportFlowUtils {
    private static final String SHARED_PREFERENCE_NAME = "ReportFlow";

    public static String getStringValue(Context context, String name,String defValue) {
        String value = defValue;
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences != null) {
            value = sharedPreferences.getString(name, defValue);
        }
        return value;
    }

    public static boolean getBooleanValue(Context context, String name, boolean defValue) {
        boolean value = defValue;
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences != null) {
            value = sharedPreferences.getBoolean(name, defValue);
        }
        return value;
    }

    public static int getIntValue(Context context, String name, int defValue) {
        int value = defValue;
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences != null) {
            value = sharedPreferences.getInt(name, defValue);
        }
        return value;
    }

    public static float getFloatValue(Context context, String name, float defValue) {
        float value = defValue;
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences != null) {
            value = sharedPreferences.getFloat(name, defValue);
        }
        return value;
    }

    public static long getLongValue(Context context, String name, long defValue) {
        long value = defValue;
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences != null) {
            value = sharedPreferences.getLong(name, defValue);
        }
        return value;
    }

    public static void setValue(Context context, String name, String value) {
        SharedPreferences.Editor editor = getEditor(context);
        editor.putString(name, value);
        editor.commit();
    }

    public static void setValue(Context context, String name, boolean value) {
        SharedPreferences.Editor editor = getEditor(context);
        editor.putBoolean(name, value);
        editor.commit();
    }

    public static void setValue(Context context, String name, int value) {
        SharedPreferences.Editor editor = getEditor(context);
        editor.putInt(name, value);
        editor.commit();
    }

    public static void setValue(Context context, String name, float value) {
        SharedPreferences.Editor editor = getEditor(context);
        editor.putFloat(name, value);
        editor.commit();
    }

    public static void setValue(Context context, String name, long value) {
        SharedPreferences.Editor editor = getEditor(context);
        editor.putLong(name, value);
        editor.commit();
    }

    private static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    }

    private static SharedPreferences.Editor getEditor(Context context) {
        return getSharedPreferences(context).edit();
    }
}
